package com.lv.phuotbacnam.ui.adapter;

import java.util.ArrayList;
import java.util.List;


import com.lv.phuotbacnam.ui.fragment.MyItem;
import com.lv.phuotbacnam.ui.fragment.MyItem_Baidang;
import com.lv.phuotbacnam.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class TListViewApdapter extends BaseAdapter
{
	private Activity activity;
	private ArrayList<MyItem_Baidang> arrItem;
	private static LayoutInflater inflater=null;
	
	
	public TListViewApdapter(ArrayList<MyItem_Baidang> arrItem, Activity activity) {
		super();
		this.arrItem = arrItem;
		this.activity = activity;
		inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return this.arrItem.size();
	}

	@Override
	public Object getItem(int arg0) {
		// TODO Auto-generated method stub
		return arg0;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}
	

	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		Log.e("position",position +"");
		Log.e("size of arraylist", arrItem.size()+"");
		if (convertView == null) {
            //LayoutInflater mInflater = (LayoutInflater) context
            //        .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
            //convertView = mInflater.inflate(R.layout.this,null);
			//convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_listview_baidang, null);
			convertView = inflater.inflate(R.layout.item_listview_baidang, null);
		}
		
		
		ImageView imgitem=(ImageView) convertView.findViewById(R.id.image_diadiem); 		//image
		TextView tv_tenbaidang = (TextView)convertView.findViewById(R.id.tv_tenbaidang);	//ten bai dang
		TextView tv_camnhan = (TextView)convertView.findViewById(R.id.tv_camnhan);			//cam nhan
		
		tv_tenbaidang.setText(arrItem.get(position).getTenbaidang());
		String image = arrItem.get(position).getUrlImage();
		tv_camnhan.setText(arrItem.get(position).getCamnhan());
		
		
		ImageLoader imageLoader;
		imageLoader = ImageLoader.getInstance();
		
		//cache image
		//DisplayImageOptions options = new DisplayImageOptions.Builder().cacheInMemory(true)
		//				.cacheOnDisc(true).resetViewBeforeLoading(true).build();
		
        //Initialize ImageLoader with configuration. Do it once.
        //imageLoader.init(ImageLoaderConfiguration.createDefault(parent.getContext()));
		//imageLoader.displayImage(image,imgitem,options);
        imageLoader.displayImage(image,imgitem);
		return convertView;
	}

}
